﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using SlaughterItem.Common.Domains.Check_Ins;
using SlaughterItem.Common.Domains.ListWeek2;
using SlaughterItem.Common.Domains.UPCTable;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.BasicSettings
{
    public class SlaughteredManageHandler : IRequestHandler<SlaughteredManageCommend, Result>
    {
        private readonly IBaseRepositoryGet<Slaughteredtes> Slaughtered;

        public SlaughteredManageHandler(IBaseRepositoryGet<Slaughteredtes> Slaughtered)
        {
            this.Slaughtered = Slaughtered;
        }

        public async Task<Result> Handle(SlaughteredManageCommend request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                var list = await Slaughtered.GetAll().Where(x => x.SlaughteredId == request.SlaughteredId).FirstOrDefaultAsync();

                if (list != null)
                {
                    result.Code = (int)CommonErrorCode.Success;
                    result.Data = list;
                    result.Msg = "反填成功";
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
